#ifndef GAME_SERVER_H
#define GAME_SERVER_H

#include <boost/asio.hpp>
#include <memory>
#include <set>
#include <client/client_session.h>

using boost::asio::ip::tcp;

class GameServer {
public:
	GameServer(boost::asio::io_context& io_context, short port);
	void join(std::shared_ptr<ClientSession> session);
	void leave(std::shared_ptr<ClientSession> session);
	void broadcast(const mcseerserver::ServerMessage& msg, std::shared_ptr<ClientSession> exclude = nullptr);
	int get_next_player_id() { return next_player_id_++; }

private:
	void start_accept();
	void handle_accept(std::shared_ptr<ClientSession> session, const boost::system::error_code& error);

	boost::asio::io_context& io_context_;
	tcp::acceptor acceptor_;
	std::set<std::shared_ptr<ClientSession>> sessions_;
	int next_player_id_;

};


#endif